/**
 * Copyright (c) 2000-2011 Liferay, Inc. All rights reserved.
 *
 * This library is free software; you can redistribute it and/or modify it under
 * the terms of the GNU Lesser General Public License as published by the Free
 * Software Foundation; either version 2.1 of the License, or (at your option)
 * any later version.
 *
 * This library is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
 * details.
 */

package doan.quanlycanbo.portlet.service.impl;

import java.util.List;

import com.liferay.counter.service.CounterLocalServiceUtil;
import com.liferay.portal.kernel.exception.PortalException;
import com.liferay.portal.kernel.exception.SystemException;
import com.liferay.portal.model.ResourceConstants;

import doan.quanlycanbo.portlet.NoSuchxuatthanException;
import doan.quanlycanbo.portlet.model.hocvi;
import doan.quanlycanbo.portlet.model.xuatthan;
import doan.quanlycanbo.portlet.service.base.xuatthanLocalServiceBaseImpl;

/**
 * 
 * @author Nguyen Tuan Vinh
 */
public class xuatthanLocalServiceImpl extends xuatthanLocalServiceBaseImpl {
	
	public List<xuatthan> getAll() throws SystemException{
		return xuatthanPersistence.findAll();
	}
	
	public xuatthan addXuatThan(xuatthan xuatthan1, long userId) throws SystemException{
		long maxuatthan = CounterLocalServiceUtil.increment(xuatthan.class.getName());
		xuatthan xuatthan2 = xuatthanPersistence.create(maxuatthan);
		xuatthan2.setGroupId(xuatthan1.getGroupId());
		xuatthan2.setCompanyId(xuatthan1.getCompanyId());
		xuatthan2.setLanguageId(xuatthan1.getLanguageId());
		xuatthan2.setTenxuatthan(xuatthan1.getTenxuatthan());

		try {
			resourceLocalService.addResources(xuatthan1.getCompanyId(), xuatthan1.getGroupId(), userId, 
					hocvi.class.getName(), xuatthan2.getPrimaryKey(), false, true, true);
		} catch (PortalException e) {
			e.printStackTrace();
		}
		
		return xuatthanPersistence.update(xuatthan2, false);
	}
	
	public xuatthan updateXuatThan(long maxuatthan, String tenxuatthan) throws SystemException, NoSuchxuatthanException{
		xuatthan xuatThan = xuatthanPersistence.findByPrimaryKey(maxuatthan);
		xuatThan.setTenxuatthan(tenxuatthan);
		return xuatthanPersistence.update(xuatThan, false);
	}
	
	public xuatthan deleteXuatThan(long maxuatthan) throws SystemException, NoSuchxuatthanException,PortalException{
		xuatthan xuatThan = xuatthanPersistence.findByPrimaryKey(maxuatthan);
		return deleteXuatThan(xuatThan);
	}
	
	public xuatthan deleteXuatThan(xuatthan xuatThan) throws SystemException,PortalException{
		resourceLocalService.deleteResource(xuatThan.getCompanyId(), xuatthan.class.getName(), ResourceConstants.SCOPE_INDIVIDUAL, xuatThan.getPrimaryKey());
		return xuatthanPersistence.remove(xuatThan);
	}
}